<html>
    <head>
        <title>FlashPlus</title>
        <script src="../js/logger.js" type="text/javascript">
        </script>
        <script type = "text/javascript">
            var FlashPlus = {
                handlers: {
                    "getOptions": function(request, sender, sendResponse){
                        sendResponse(localStorage);
                    },
                    "setFlashIcon": function(request, sender, sendResponse){
                        chrome.pageAction.show(sender.tab.id);
                        sendResponse();
                    },
                    "openPage": function(request, sender, sendResponse){
                        chrome.tabs.create({
                            "url": request.data.url
                        });
                        sendResponse(tab);
                    },
                    "popout": function(request, sender, sendResponse){
                        var me = this;
                        chrome.windows.create({
                            "url": request.data.url
                        }, function(window){
                            chrome.tabs.getSelected(window.id, function(tab){
                                chrome.tabs.executeScript(tab.id, {
                                    "code": request.data.code
                                });
                            });
                            __logger__.log(request.data.code)
                            sendResponse(window);
                        });
                    },
                },
                
                init: function(){
                    var me = this;
                    var defaultOptions = {
                        "maxCheckTime": 60,
                        "canLoadOnStartup": true,
                        "enableLogging": false
                    };
                    for (var x in defaultOptions) {
                        localStorage[x] = localStorage[x] || defaultOptions[x];
                    }
                    
                    chrome.extension.onRequest.addListener(function(request, sender, sendResponse){
                        if (typeof(me.handlers[request.action]) === "function") {
                            me.handlers[request.action].apply(me, [request, sender, sendResponse]);
                        }
                    });
                },
            }
            FlashPlus.init();
            __logger__.enableLogging(localStorage.enableLogging);
        </script>
    </head>
</html>
